<?php

namespace App\Http\Requests\service;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait CompensateRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'currency_id' => 'required|integer',
            'amount' => 'required|numeric',
            'pod_file' => 'required',
            'letter_file' => 'required',
            'lose_invoice' => 'required',
            'whole_invoice' => 'required',
            'lose_list' => 'required',
            'whole_list' => 'required',
            'pic_file' => 'required',
        ], [
            'currency_id.required' => '请选择币种',
            'amount.required' => '请填写金额',
            'pod_file.required' => '请上传POD文件',
            'letter_file.required' => '请上传索赔信',
            'lose_invoice.required' => '请上传丢件发票',
            'whole_invoice.required' => '请上传整票发票',
            'lose_list.required' => '请上传丢件箱单',
            'whole_list.required' => '请上传整票箱单',
            'pic_file.required' => '请上传图片附件'
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }


    public static function confirm_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'actual_currency_id' => 'required|integer',
            'actual_amount' => 'required|numeric',
//            'compensate_remarks' => 'required',
        ], [
            'actual_currency_id.required' => '请选择币种',
            'actual_amount.required' => '请填写金额',
//            'compensate_remarks.required' => '请填写备注',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
